package com.xjy.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjy.common.core.mybatisplus.core.ServicePlusImpl;
import com.xjy.common.core.page.PagePlus;
import com.xjy.common.core.page.TableDataInfo;
import com.xjy.common.utils.PageUtils;
import com.xjy.system.domain.ReportExpendBudgetDetail;
import com.xjy.system.domain.ReportLoanDetail;
import com.xjy.system.domain.bo.ReportLoanDetailQueryBo;
import com.xjy.system.domain.vo.ReportLoanDetailVo;
import com.xjy.system.mapper.ReportLoanDetailMapper;
import com.xjy.system.service.IReportLoanDetailService;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 借款明细表Service业务层处理
 *
 * @author mlb
 * @date 2022-03-23
 */
@Service
public class ReportLoanDetailServiceImpl extends ServicePlusImpl<ReportLoanDetailMapper, ReportLoanDetail> implements IReportLoanDetailService {

    @Override
    public ReportLoanDetailVo queryById(Long projId){
        return getVoById(projId, ReportLoanDetailVo.class);
    }

    @Override
    public TableDataInfo<ReportLoanDetailVo> queryPageList(ReportLoanDetailQueryBo bo) {
        PagePlus<ReportLoanDetail, ReportLoanDetailVo> result = pageVo(PageUtils.buildPagePlus(), buildQueryWrapper(bo), ReportLoanDetailVo.class);
        return PageUtils.buildDataInfo(result);
    }

    @Override
    public List<ReportLoanDetailVo> queryList(ReportLoanDetailQueryBo bo) {
        return listVo(buildQueryWrapper(bo), ReportLoanDetailVo.class);
    }

    private LambdaQueryWrapper<ReportLoanDetail> buildQueryWrapper(ReportLoanDetailQueryBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLoanDetail> lqw = Wrappers.lambdaQuery();
        lqw.eq(StrUtil.isNotBlank(bo.getBorrower()), ReportLoanDetail::getBorrower, bo.getBorrower());
        lqw.between(params.get("beginTransactiondate") != null && params.get("endTransactiondate") != null,
            ReportLoanDetail::getTransactiondate ,params.get("beginTransactiondate"), params.get("endTransactiondate"));
		lqw.eq(null != bo.getProjId(), ReportLoanDetail::getProjId,bo.getProjId());
		lqw.eq(null != bo.getBorrowerId(),ReportLoanDetail::getBorrowerId,bo.getBorrowerId());
        return lqw;
    }

}
